package com.kingdee.eas.custom.hr.attendance.app;

import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.hr.attendance.NightPaymentCollection;
import com.kingdee.eas.custom.hr.attendance.NightPaymentInfo;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.UuidException;

public class NightPaymentControllerBean extends
		AbstractNightPaymentControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.custom.hr.attendance.app.NightPaymentControllerBean");

	@Override
	protected IObjectCollection _getNightPaymentAndHalfCollection(Context ctx)
			throws BOSException, EASBizException {

		NightPaymentCollection collection = new NightPaymentCollection();

		StringBuffer buffer = new StringBuffer();

		buffer.append("	SELECT A.FID      AS FID,			\n");
		buffer.append("	       A.FNUMBER  AS FNUMBER,		\n");
		buffer.append("	       A.FNAME_L2 AS FNAME,			\n");
		buffer.append("	       A.CFMONEY  AS FMONEY,		\n");
		buffer.append("	       A.CFHALF   AS FHALF,			\n");
		buffer.append("	       B.FID      AS HID,			\n");
		buffer.append("	       B.FNUMBER  AS HNUMBER,		\n");
		buffer.append("	       B.FNAME_L2 AS HNAME,			\n");
		buffer.append("	       B.CFMONEY  AS HMONEY,		\n");
		buffer.append("	       B.CFHALF   AS HHALF			\n");
		buffer.append("	  FROM CT_KQ_NIGHTPAYMENT A			\n");
		buffer.append("	  LEFT JOIN CT_KQ_NIGHTPAYMENT B	\n");
		buffer.append("	    ON A.FID = B.CFSTANDARDID		\n");
		buffer.append("	 WHERE A.CFHALF = 0					\n");

		IRowSet rs = DbUtil.executeQuery(ctx, buffer.toString());
		try {
			while (rs.next()) {
				NightPaymentInfo payment = new NightPaymentInfo();

				payment.setId(BOSUuid.read(rs.getString("FID")));
				payment.setNumber(rs.getString("FNUMBER"));
				payment.setName(rs.getString("FNAME"));
				payment.setMoney(rs.getBigDecimal("FMONEY"));
				payment.setHalf(rs.getBoolean("FHALF"));

				NightPaymentInfo half = new NightPaymentInfo();

				half.setId(BOSUuid.read(rs.getString("HID")));
				half.setNumber(rs.getString("HNUMBER"));
				half.setName(rs.getString("HNAME"));
				half.setMoney(rs.getBigDecimal("HMONEY"));
				half.setHalf(rs.getBoolean("HHALF"));

				payment.put("HALF", half);

				collection.add(payment);
			}
		} catch (Exception e) {
			throw new BOSException(e);
		}
		return collection;
	}
}